#ifdef __QT5_TARGET

#include <QtCore/QEvent>
#include <QtCore/QTimer>
#include <QtWidgets/QComboBox>

#else

#include <QEvent>
#include <QTimer>
#include <QComboBox>

#endif

#include "selectTextEventHandler.h"
#include "NullPointerException.h"

selectTextEventHandler::selectTextEventHandler(QObject* parent):QObject(parent)
{
}

selectTextEventHandler::~selectTextEventHandler(void)
{
}

bool selectTextEventHandler::eventFilter(QObject *object, QEvent *event)
{
	
	if(event->type() == QEvent::FocusIn)
	{
		QComboBox* combo = dynamic_cast<QComboBox*>(object);
		if(combo == NULL)
		{
				NullPointerException npe;
				npe.setMessage("Select text event handler was connected to a wrong widget");
				throw npe;
				return false;
		}
		else
		{
			QLineEdit* lineEdit = combo->lineEdit();
			QTimer::singleShot(0, lineEdit, SLOT(selectAll()));


			return false;
		}
	}
	
	return QObject::eventFilter(object,event);
}